package com.wzcl.app.dao.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.wzcl.app.dao.model.common.Base;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


@Getter
@Setter
@Entity
@Table(name = "Course",
        indexes = {
                @Index(columnList = "courseType")
        }
)
@ApiModel(value = "课程表")
@EntityListeners(AuditingEntityListener.class)
@ToString
@JsonIgnoreProperties(value = {"workShowList"})
public class Course implements Base, Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @JSONField(serialize = false)
    @ManyToOne
    @JoinColumn(name = "subjectId")
    @ApiModelProperty(value = "科目")
    private Subject subject;

    @JSONField(serialize = false)
    @ManyToOne
    @JoinColumn(name = "gradeId")
    @ApiModelProperty(name = "年级")
    private Grade grade;

    @ApiModelProperty(value = "名称")
    private String name;

    @ApiModelProperty(value = "描述")
    private String description;

    @ApiModelProperty(value = "难度")
    private Integer hard;

    @ApiModelProperty(value = "创建时间")
    @CreatedDate
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    @ApiModelProperty(value = "更新时间")
    @LastModifiedDate
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date updateTime;

    @ApiModelProperty(value = "是否含有资料")
    private Boolean haveBook;

    @ApiModelProperty(value = "课程状态")
    private Integer courseState;

    @ApiModelProperty(value = "课时数")
    private Integer count;

    @ApiModelProperty(value = "课程类型")
    private Integer courseType;

    @ApiModelProperty(value = "开始课程时间")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date startDate;

    @ApiModelProperty(value = "结束课程时间")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date endDate;

    @ApiModelProperty(value = "每天开始时间")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date startTime;

    @ApiModelProperty(value = "每天结束时间")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date endTime;

    @ApiModelProperty(value = "开始时间的前缀")
    private String timePrefix;

    @ApiModelProperty(value = "状态")
    private Integer state;

    @ApiModelProperty(value = "课程图片")
    private String pictures;

    @ApiModelProperty(value = "海报")
    @Column(columnDefinition = "TEXT")
    private String posters;

    @ApiModelProperty(value = "虚拟观看数")
    private Long viewVolume;

    @ApiModelProperty(value = "实际观看数")
    private Long realViewVolume;

    @ApiModelProperty(value = "虚拟销售数")
    private Integer saleVolume;

    @ApiModelProperty(value = "实际销售数")
    private Integer realSaleVolume;

    @ApiModelProperty("实际观看数+虚拟观看数")
    private Long viewVolumeSort;

    @JSONField(serialize = false)
    @ManyToOne(fetch = FetchType.LAZY)
    @ApiModelProperty(value = "商品")
    @JoinColumn(name = "commodityId")
    private Commodity commodity;

    @OneToMany(mappedBy = "course")
    List<WorkShow> workShowList = new ArrayList<>();
}